home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 1 / Mac Magazin and MacEasy Magazine CD - Issue 01.iso / Sharewarebibliothek / Powermac / C64 / SOURCE / AppleEvents.c < prev    next >
Text File  |  1994-06-06  |  7KB  |  265 lines

  1. /*
  2.     Commodore 64 Emulator v0.4      Earle F. Philhower III
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include <AppleEvents.h>
  21. #include "Processor.h"
  22. #include "Error.h"
  23. #include "FileTypes.h"
  24.  
  25.  
  26. int AppleEventInitialize(void);
  27.  
  28. OSErr DoQUIT(void), DoOAPP(void);
  29. OSErr DoODOC(const AppleEvent *theAE,const AppleEvent *theRp);
  30. OSErr DoPDOC(const AppleEvent *theAE,const AppleEvent *theRp);
  31.  
  32. extern void CleanUpCommodore(void);
  33.  
  34. void OpenFSSpec(FSSpec *spec);
  35. void PrintFSSpec(FSSpec *spec);
  36. void AttachFloppyImage(FSSpec *spec);
  37. void LoadRAMFS(FSSpec *spec);
  38. void LoadTapeFS(FSSpec *spec);
  39.  
  40. #ifndef __MWERKS__
  41. pascal OSErr AEHandleQUIT(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  42. pascal OSErr AEHandleOAPP(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  43. pascal OSErr AEHandleODOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  44. pascal OSErr AEHandlePDOC(const AppleEvent *theAE,const AppleEvent *theRp, long RC);
  45. #else
  46. static AEEventHandlerUPP myQUITAEHandler = NULL;
  47. static AEEventHandlerUPP myOAPPAEHandler = NULL;
  48. static AEEventHandlerUPP myODOCAEHandler = NULL;
  49. static AEEventHandlerUPP myPDOCAEHandler = NULL;
  50.  
  51. pascal OSErr AEHandleQUIT(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
  52. pascal OSErr AEHandleOAPP(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
  53. pascal OSErr AEHandleODOC(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
  54. pascal OSErr AEHandlePDOC(const AppleEvent *theAE,const AEEventHandlerUPP *theRp, long RC);
  55. #endif
  56.  
  57.  
  58.  
  59. static DescType missedTypeCode;
  60. static long missedActualSize;
  61. #define InstallFinder(z,y) AEInstallEventHandler(kCoreEventClass, z, y, 0, false)
  62. #define MissedParams(z) \
  63.     (AESizeOfAttribute(z, keyMissedKeywordAttr, \
  64.         &missedTypeCode, &missedActualSize) != errAEDescNotFound)
  65.  
  66.  
  67. OSErr DoQUIT(void)
  68. {
  69.     CleanUpCommodore();
  70.     ExitToShell();
  71. }
  72.  
  73. pascal OSErr AEHandleQUIT(theAppleEvent, theReply, theRefCon)
  74. const AppleEvent *theAppleEvent, *theReply;
  75. long theRefCon;
  76. {
  77.     OSErr err=noErr;
  78.  
  79.     err = DoQUIT();
  80.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  81.     /* There should be NO parameters sent to us..if there are, someone's
  82.         got a REAL problem! (not us, though!) */
  83.     
  84.     return(err);
  85. }
  86.  
  87. OSErr DoOAPP()
  88. {
  89.     return noErr;
  90. }
  91.  
  92. pascal OSErr AEHandleOAPP(theAppleEvent, theReply, theRefCon)
  93. const AppleEvent *theAppleEvent, *theReply;
  94. long theRefCon;
  95. {
  96.     OSErr err=noErr;
  97.     
  98.     err = DoOAPP();
  99.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  100.     
  101.     return(err);
  102. }
  103.  
  104. void OpenFSSpec(FSSpec *spec)
  105. {
  106.     FInfo fInfo;
  107.     
  108.     FSpGetFInfo(spec, &fInfo);
  109.     switch(fInfo.fdType)
  110.     {
  111.     case DISKFTYPE:
  112.         AttachFloppyImage(spec);
  113.         break;
  114.     case RAMFTYPE:
  115.         LoadRAMFS(spec);
  116.         break;
  117.     case PRINTERFTYPE:
  118.         break;
  119.     case TAPEFTYPE:
  120.         LoadTapeFS(spec);
  121.         break;
  122.     }
  123. }
  124.  
  125.  
  126. void PrintFSSpec(FSSpec *spec)
  127. {
  128.     FInfo fInfo;
  129.     
  130.     FSpGetFInfo(spec, &fInfo);
  131.     switch(fInfo.fdType)
  132.     {
  133.     case DISKFTYPE:
  134.         break;
  135.     case RAMFTYPE:
  136.         break;
  137.     case PRINTERFTYPE:
  138.         break;
  139.     case TAPEFTYPE:
  140.         break;
  141.     }
  142. }
  143.  
  144. OSErr DoODOC(theAppleEvent, theReply)
  145. const AppleEvent *theAppleEvent, *theReply;
  146. {
  147.     OSErr err;
  148.     FSSpec myFSS;
  149.     AEDescList *docList;
  150.     long items;
  151.     long index;
  152.     AEKeyword keywd;
  153.     DescType typeCode;
  154.     Size actualSize;
  155.  
  156.     err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
  157.     if (err!=noErr) return (err);
  158.     
  159.     err = AECountItems(docList, &items);
  160.     if (err!=noErr) return (err);
  161.     
  162.     for (index=1; index<=items; index++)
  163.     {
  164.         err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode,(Ptr)&myFSS,
  165.                     sizeof(myFSS), &actualSize );
  166.         if (err!=noErr)
  167.         {
  168.             AEDisposeDesc(docList);
  169.             return (err);
  170.         }
  171.         OpenFSSpec(&myFSS);
  172.     }
  173.  
  174.     err = AEDisposeDesc(docList);
  175.     return(err);
  176. }
  177.  
  178.  
  179.  
  180. pascal OSErr AEHandleODOC(theAppleEvent, theReply, theRefCon)
  181. const AppleEvent *theAppleEvent, *theReply;
  182. long theRefCon;
  183. {
  184.     OSErr err=noErr;
  185.     
  186.     err = DoODOC(theAppleEvent, theReply);
  187.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  188.     
  189.     return(err);
  190. }
  191.  
  192.  
  193. OSErr DoPDOC(theAppleEvent, theReply)
  194. const AppleEvent *theAppleEvent, *theReply;
  195. {
  196.     OSErr err;
  197.     FSSpec myFSS;
  198.     AEDescList *docList;
  199.     long items;
  200.     long index;
  201.     AEKeyword keywd;
  202.     DescType typeCode;
  203.     Size actualSize;
  204.  
  205.     err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
  206.     if (err!=noErr) return (err);
  207.     
  208.     err = AECountItems(docList, &items);
  209.     if (err!=noErr) return (err);
  210.     
  211.     for (index=1; index<=items; index++)
  212.     {
  213.         err = AEGetNthPtr(docList, index, typeFSS, &keywd, &typeCode, (Ptr)&myFSS,
  214.                     sizeof(myFSS), &actualSize );
  215.         if (err!=noErr)
  216.         {
  217.             AEDisposeDesc(docList);
  218.             return (err);
  219.         }
  220.         PrintFSSpec(&myFSS);
  221.     }
  222.  
  223.     err = AEDisposeDesc(docList);
  224.     return(err);
  225. }
  226.  
  227.  
  228.  
  229. pascal OSErr AEHandlePDOC(theAppleEvent, theReply, theRefCon)
  230. const AppleEvent *theAppleEvent, *theReply;
  231. long theRefCon;
  232. {
  233.     OSErr err=noErr;
  234.     
  235.     err = DoPDOC(theAppleEvent, theReply);
  236.     if (MissedParams(theAppleEvent) && err==noErr) err = errAEParamMissed;
  237.     
  238.     return(err);
  239. }
  240.  
  241.     
  242.  
  243. int AppleEventInitialize(void)
  244. {
  245. #ifndef __MWERKS__
  246.     if (InstallFinder(kAEQuitApplication, AEHandleQUIT)) return kAppleEventError;
  247.     if (InstallFinder(kAEOpenApplication, AEHandleOAPP)) return kAppleEventError;
  248.     if (InstallFinder(kAEOpenDocuments, AEHandleODOC)) return kAppleEventError;
  249.     if (InstallFinder(kAEPrintDocuments, AEHandlePDOC)) return kAppleEventError;
  250. #else
  251.     myQUITAEHandler = NewAEEventHandlerProc(AEHandleQUIT);
  252.     myOAPPAEHandler = NewAEEventHandlerProc(AEHandleOAPP);
  253.     myODOCAEHandler = NewAEEventHandlerProc(AEHandleODOC);
  254.     myPDOCAEHandler = NewAEEventHandlerProc(AEHandlePDOC);
  255.  
  256.     if (InstallFinder(kAEQuitApplication, myQUITAEHandler)) return kAppleEventError;
  257.     if (InstallFinder(kAEOpenApplication, myOAPPAEHandler)) return kAppleEventError;
  258.     if (InstallFinder(kAEOpenDocuments, myODOCAEHandler)) return kAppleEventError;
  259.     if (InstallFinder(kAEPrintDocuments, myPDOCAEHandler)) return kAppleEventError;
  260. #endif
  261.  
  262.     return kNoError;
  263. }
  264.  
  265.